
public class LeetCode553 {

    public static void main(String[] args) {
        System.out.println(optimalDivision(new int[]{1000, 100, 10, 2}));
    }

    public static String optimalDivision(int[] nums) {
        if (nums.length == 1) {
            return String.valueOf(nums[0]);
        }

        if (nums.length == 2) {
            return nums[0] + "/" + nums[1];
        }

        StringBuilder s = new StringBuilder();

        s.append(nums[0]).append("/(");
        for (int i = 1; i < nums.length; i++) {
            if (i == nums.length - 1) {
                s.append(nums[i]);
                continue;
            }

            s.append(nums[i]).append("/");
        }
        s.append(")");


        return s.toString();
    }
}
